package com.example.mapp.buildSql;

import org.apache.ibatis.jdbc.SQL;

import com.example.ext.entity.ExtPromotionRecord;

/**
 * Created by douyx on 2018/05/15.
 */
public class PromotionMappSql {

	/**
	 * 获取杂物电梯维保数据
	 * 
	 * @param promotionRecord
	 * @return
	 */
	public String findRecord(final ExtPromotionRecord promotionRecord) {

		String select = " * ";

		String table = " promotion_record ";
		String conditions = "  1=1 ";
		conditions += " and user_id = #{userId} and type = #{type}";
		if (null != promotionRecord.getAddedTimeFrom() && !promotionRecord.getAddedTimeFrom().equals("")) {
			conditions += " and added_time >= #{addedTimeFrom}";
		}
		if (null != promotionRecord.getAddedTimeTo() && !promotionRecord.getAddedTimeTo().equals("")) {
			conditions += " and added_time <= #{addedTimeTo}";
		}
		String finalConditions = conditions;
		return new SQL() {
			{
				SELECT(select);
				FROM(table);
				WHERE(finalConditions);
				ORDER_BY("added_time desc");
			}
		}.toString();
	}
}
